/*
 * @Author: sunkai@xinxinapp.cn
 * @Date: 2021-03-08 18:28:34
 * @LastEditTime: 2021-03-09 15:49:57
 * @LastEditors: sunkai@xinxinapp.cn
 * @Description:
 * @FilePath: /edu/src/store/index.ts
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: JSON.parse(window.localStorage.getItem('user') || 'null')
  },
  mutations: {
    setUser (state, payload) {
      state.user = JSON.parse(payload)

      // 为了防止页面刷新数据丢失，我们需要把 user 数据持久化
      window.localStorage.setItem('user', payload)
    }
  },
  actions: {
  },
  modules: {
  }
})
